package com.mission.schedule.activity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lcf.refreshlibrary.PullToRefreshBase;
import com.lcf.refreshlibrary.PullToRefreshScrollView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.mission.schedule.R;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.NoteLYBean;
import com.mission.schedule.bean.qd606.NoteTitleDetailBean;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.constants.URLConstants;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.ListViewForScrollView;
import com.mission.schedule.utils.ProgressUtil;
import com.mission.schedule.utils.SharedPrefUtil;
import com.mission.schedule.utils.StringUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;


@SuppressLint({"SimpleDateFormat", "HandlerLeak"})
public class QDFXDetailLYActivity extends BaseActivity implements OnClickListener {


    private LinearLayout back, ll;
    private RelativeLayout my_friend_ll_right;
    private TextView title_tv,username,send;
    private ListViewForScrollView listview;
    PullToRefreshScrollView scrollview;
    EditText edit_tv;

    Context context;

    SharedPrefUtil sharedPrefUtil = null;

    String content;
    String titleId;
    String title;
    int id = 0,style = 0;
    String time;
    String nametime;
    String userid;
    String uid;

    ListAdapter listAdapter;
    boolean isOnRefresh = false;
    int wheretype = 0;
    String where = "";

    @Override
    protected void setListener() {
        back.setOnClickListener(this);
        my_friend_ll_right.setOnClickListener(this);
        edit_tv.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (edit_tv.getLineCount() <= 4) {
                    ViewGroup.LayoutParams llp = ll.getLayoutParams();
                    llp.height = edit_tv.getLineCount() * 66 + 125;
                    ll.requestLayout();
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                alterImportantDialog(QDFXDetailLYActivity.this, itemsBeanList.get(position).mess, 1,position);
            }
        });
        send.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (edit_tv.getText().toString().isEmpty()){
                    Toast.makeText(QDFXDetailLYActivity.this,"留言内容不能为空",Toast.LENGTH_SHORT).show();
                } else {
                    ly(edit_tv.getText().toString(),0);
                }
            }
        });
        scrollview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {


            @Override
            public void onPullDownToRefresh(
                    PullToRefreshBase<ScrollView> refreshView) {
                isOnRefresh = true;
                load();
            }

            @Override
            public void onPullUpToRefresh(
                    PullToRefreshBase<ScrollView> refreshView) {
                scrollview.onRefreshComplete();
            }
        });
    }


    @Override
    protected void setContentView() {
        setContentView(R.layout.dx_detail_ly_activity);
        content = getIntent().getStringExtra("content");
        titleId = getIntent().getStringExtra("titleid");
        title = getIntent().getStringExtra("title");
        id = getIntent().getIntExtra("id",0);
        style = getIntent().getIntExtra("style",0);
        nametime = getIntent().getStringExtra("nametime");
        uid = getIntent().getStringExtra("uid");
        wheretype = getIntent().getIntExtra("wheretype",0);
        if (wheretype == 1){
            where = getIntent().getStringExtra("where");
        }

        username = (TextView) findViewById(R.id.username);
        send = (TextView) findViewById(R.id.send);
        back = (LinearLayout) findViewById(R.id.top_ll_back);
        ll = (LinearLayout) findViewById(R.id.ll);
        my_friend_ll_right = (RelativeLayout) findViewById(R.id.my_friend_ll_right);
        title_tv = (TextView) findViewById(R.id.title);
        listview = (ListViewForScrollView) findViewById(R.id.listview);
        View foolview = LayoutInflater.from(this).inflate(R.layout.emptry_foolterview_white, null);
        listview.addFooterView(foolview, null, false);
        scrollview = (PullToRefreshScrollView) findViewById(R.id.scrollview);
        edit_tv = (EditText) findViewById(R.id.edit_tv);
        if (id == 0){
            title_tv.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            username.setVisibility(View.VISIBLE);
            username.setText(nametime);
        }
        App.getDBcApplication().updateAllNoteLYDataIsNew(titleId,id,0);
        lyadapter();
        load();
    }

    private void load() {
        HttpUtils httpUtils0 = new HttpUtils(5000);
        RequestParams params0 = new RequestParams();
        params0.addBodyParameter("titleId", titleId);
        params0.addBodyParameter("type", "5");
        params0.addBodyParameter("uId", uid);
        params0.addBodyParameter("nowPage", "1");
        params0.addBodyParameter("pageNum", "2000");
        params0.addBodyParameter("id", id+"");
        params0.addBodyParameter("changeTime", App.getDBcApplication().getOneNoteLYDataDownTime(titleId).isEmpty() ? "" :
                App.getDBcApplication().getOneNoteLYDataDownTime(titleId).replace("T"," "));
        httpUtils0.send(HttpMethod.POST, URLConstants.清单留言查询留言主表, params0, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    NoteLYBean noteLYBean = gson.fromJson(responseInfo.result, NoteLYBean.class);
                    if (noteLYBean.status == 0) {
                        List<NoteLYBean.PageBean.ItemsBean> list = noteLYBean.page.items;
                        if (list != null) {
                            for (NoteLYBean.PageBean.ItemsBean bean : list) {
                                App.getDBcApplication().insertNoteLYData(bean, noteLYBean.downTime.replace("T"," "));
                            }
                            lyadapter();
                        }
                    }
                }
                if (isOnRefresh){
                    scrollview.onRefreshComplete();
                    isOnRefresh = false;
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {

            }
        });
    }

    List<NoteLYBean.PageBean.ItemsBean> itemsBeanList = new ArrayList<>();

    private void lyadapter() {
        if (wheretype == 1) {
            if (where.isEmpty()) {
                where = " cId = 0 ";
            }
        } else {
            where = " cId = " + id;
        }
        itemsBeanList = App.getDBcApplication().getAllNoteLYData(titleId, where);
        Collections.sort(itemsBeanList, new Comparator<NoteLYBean.PageBean.ItemsBean>() {
            @Override
            public int compare(NoteLYBean.PageBean.ItemsBean lhs, NoteLYBean.PageBean.ItemsBean rhs) {
                return DateUtil.parseDateTimeSs(rhs.changeTime.replace("T"," ")).compareTo(DateUtil.parseDateTimeSs(lhs.changeTime.replace("T"," ")));
            }
        });
        listAdapter = new ListAdapter(itemsBeanList);
        listview.setAdapter(listAdapter);
        listAdapter.notifyDataSetChanged();

    }

    @Override
    protected void init(Bundle savedInstanceState) {
        context = this;

        sharedPrefUtil = new SharedPrefUtil(context, ShareFile.USERFILE);

        userid = sharedPrefUtil.getString(this, ShareFile.USERFILE, ShareFile.USERID, "");

        if (!content.isEmpty()) {
            setcolor(content, title_tv);
        }
    }

    @Override
    protected void setAdapter() {

        scrollview.post(new Runnable() {
            @Override
            public void run() {
                scrollview.scrollTo(0, 0);
            }
        });
        title_tv.setFocusable(true);
        title_tv.setFocusableInTouchMode(true);
        title_tv.requestFocus();

    }

    ProgressUtil progressUtil = new ProgressUtil();

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.top_ll_back:
                onBackPressed();
                break;
            case R.id.my_friend_ll_right:
                alterImportantDialog(QDFXDetailLYActivity.this, content, 0,0);
                break;
            default:
                break;
        }
    }


    @Override
    public void onBackPressed() {
        this.finish();
        super.onBackPressed();
    }

    /**
     * 点击留言
     */
    private void alterImportantDialog(Context context, String message, int type,int position) {
        Dialog dialog = new Dialog(context, R.style.dialog_translucent_adjustPan);
        Window window = dialog.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.add_reply_dialogs, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        dialog.show();

        new alterImportantDialogOnClick(context, dialog, more_pop_menu, message, type, position);
    }

    class alterImportantDialogOnClick implements View.OnClickListener {

        private View view;
        private Dialog dialog;
        private TextView addnote_tv;
        private TextView copy_tv;
        private TextView canel_tv;
        private String message;
        private Context context;
        int type;int position;

        @SuppressLint("NewApi")
        public alterImportantDialogOnClick(Context context, Dialog dialog, View view, String message, int type ,int position) {
            this.dialog = dialog;
            this.view = view;
            this.message = message;
            this.context = context;
            this.type = type;
            this.position = position;
            initview();
        }

        private void initview() {
            copy_tv = (TextView) view.findViewById(R.id.copy_tv);
            copy_tv.setOnClickListener(this);
            if (type == 1) {
                copy_tv.setText("复制留言内容");
            }
            canel_tv = (TextView) view.findViewById(R.id.canel_tv);
            canel_tv.setOnClickListener(this);
            addnote_tv = (TextView) view.findViewById(R.id.addnote_tv);
            TextView delete_tv = (TextView) view.findViewById(R.id.delete_tv);
            if (uid.equals(userid) && type == 1){
                delete_tv.setVisibility(View.VISIBLE);
                addnote_tv.setVisibility(View.VISIBLE);
            }else {
                delete_tv.setVisibility(View.GONE);
                addnote_tv.setVisibility(View.VISIBLE);
            }
            delete_tv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    NoteLYBean.PageBean.ItemsBean bean = itemsBeanList.get(position);
                    delete(2,bean.id);
                }
            });
            addnote_tv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    int num = App.getDBcApplication().getTitleNoteDetailData(userid, titleId, false).size();
                    NoteTitleDetailBean.ListBean listBean = new NoteTitleDetailBean.ListBean();
                    listBean.titleId = titleId;
                    listBean.uid = Integer.valueOf(userid);
                    listBean.id = App.getDBcApplication().getMinId() - 1;
                    listBean.style = style;
                    listBean.changetime = DateUtil.nowTime();
                    listBean.createTime = DateUtil.nowTime();
                    listBean.lType = 0;
                    listBean.orderId = num + 1;
                    listBean.endstate = 0;
                    listBean.remark = "";
                    listBean.contents = message;
                    listBean.titles = title;
                    listBean.imgPath = "";
                    listBean.imgUrl = "";
                    listBean.cpath = "";
                    listBean.curl = "";
                    listBean.nums = "";
                    listBean.shareUrl = "";
                    listBean.remark1 = "";
                    listBean.remark2 = "";
                    listBean.remark3 = "";
                    listBean.remark4 = "";
                    App.getDBcApplication().saveNoteDetailData(listBean);
                    App.getDBcApplication().updateNoteTitleDetailState(listBean.titleId, listBean.id, userid, 1, false);

                    Toast.makeText(context, "加入成功", Toast.LENGTH_SHORT).show();

                    dialog.dismiss();
                }
            });
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.copy_tv:
                    // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                    // 将文本内容放到系统剪贴板里。
                    cm.setText(message);
                    Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                    break;
                case R.id.canel_tv:
                    dialog.dismiss();
                    break;
            }
        }
    }

    class ListAdapter extends BaseAdapter {

        List<NoteLYBean.PageBean.ItemsBean> list = new ArrayList<>();

        public ListAdapter(List<NoteLYBean.PageBean.ItemsBean> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            final ViewHolder holder;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = LayoutInflater.from(QDFXDetailLYActivity.this).inflate(R.layout.new_my_ly_item, parent, false);

                holder.imageView = (ImageView) convertView.findViewById(R.id.lys_icon);
                holder.name = (TextView) convertView.findViewById(R.id.lys_name);
                holder.time = (TextView) convertView.findViewById(R.id.lys_time);
                holder.message = (TextView) convertView.findViewById(R.id.lys_message);
                holder.ly_item_ll = (LinearLayout) convertView.findViewById(R.id.ly_item_ll);

                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    .showStubImage(R.mipmap.img_null_smal)          // 设置图片下载期间显示的图片
                    .showImageForEmptyUri(R.mipmap.img_null_smal)  // 设置图片Uri为空或是错误的时候显示的图片
                    .showImageOnFail(R.mipmap.img_null_smal)       // 设置图片加载或解码过程中发生错误显示的图片
                    .cacheInMemory(true)                        // 设置下载的图片是否缓存在内存中
                    .cacheOnDisc(true)                          // 设置下载的图片是否缓存在SD卡中
//                        .displayer(new RoundedBitmapDisplayer(20))  // 设置成圆角图片
                    .build();

            String imageurl = URLConstants.HOST + "/TbDU_showImage.htm?imageName=" + list.get(position).lyTitleImg + "&imageType=2&imageSizeType=3";

            ImageLoader.getInstance().displayImage(imageurl, holder.imageView, options);

            holder.time.setText(list.get(position).changeTime.replace("T", " ")+" "+list.get(position).reamrk1);
            holder.name.setText(list.get(position).lyName);
            holder.message.setText(list.get(position).mess);
            return convertView;
        }


        class ViewHolder {
            ImageView imageView;
            TextView name, time, message;
            LinearLayout ly_item_ll;
        }


    }

    //设置双#号包裹的文字颜色
    private void setcolor(String content, TextView editText) {
        if (content.length() > 1) {
            SpannableStringBuilder builder = new SpannableStringBuilder(content);
            List<Integer> integerList = new ArrayList<>();
            int index = 0;
            int count = hit(content, "#");
            if (count > 1) {
                if (count % 2 == 0) {
                    for (int i = 0; i < count; i++) {
                        if (i == 0) {
                            index = content.indexOf("#");
                        } else {
                            index = content.indexOf("#", index + 1);
                        }
                        integerList.add(index);
                    }
                    for (int i = 0; i < integerList.size(); i++) {
                        if (i > 0) {
                            if (i % 2 != 0) {
                                ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor("#df7926"));
                                builder.setSpan(span, integerList.get(i - 1), integerList.get(i) + 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                        }
                    }
                    editText.setText(builder);
                } else {
                    for (int i = 0; i < count - 1; i++) {
                        if (i == 0) {
                            index = content.indexOf("#");
                        } else {
                            index = content.indexOf("#", index + 1);
                        }
                        integerList.add(index);

                    }
                    for (int i = 0; i < integerList.size(); i++) {
                        if (i > 0) {
                            if (i % 2 != 0) {
                                ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor("#df7926"));
                                builder.setSpan(span, integerList.get(i - 1), integerList.get(i) + 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                        }
                    }
                    editText.setText(builder);
                }
            } else {
                editText.setText(content);
            }
        } else {
            editText.setText(content);
        }
        editText.setLineSpacing(20, 1.5f);
    }

    /**
     * @param a 被匹配的长字符串
     * @param b 匹配的短字符串
     * @return 匹配次数
     */
    public int hit(String a, String b) {
        if (a.length() < b.length()) {
            return 0;
        }
        char[] a_t = a.toCharArray();
        int count = 0;

        for (int i = 0; i < a.length(); i++) {
            StringBuffer buffer = new StringBuffer();
            for (int j = 0; j < b.length(); j++) {
                buffer.append(a_t[i + j]);
            }
            if (buffer.toString().equals(b)) {
                count++;
            }
        }

        return count;
    }

    private void delete(int type,final int id){
        final ProgressUtil progressUtil = new ProgressUtil();
        progressUtil.ShowProgress(context,true,true,"正在删除...");
        HttpUtils httpUtils = new HttpUtils(3000);
        RequestParams params = new RequestParams();
        params.addBodyParameter("uId", userid);
        params.addBodyParameter("type", type+"");
        params.addBodyParameter("id", id+"");
        params.addBodyParameter("titleId", titleId);
        httpUtils.send(HttpMethod.POST, URLConstants.清单留言删除主留言信息, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    DelLYBean delLYBean = gson.fromJson(responseInfo.result, DelLYBean.class);
                    if (delLYBean.status == 0){
                        App.getDBcApplication().deleteLY(id);
                    }else {
                        Toast.makeText(QDFXDetailLYActivity.this,"删除失败",Toast.LENGTH_SHORT).show();
                    }
                }
                lyadapter();
                progressUtil.dismiss();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                Toast.makeText(QDFXDetailLYActivity.this,"网络异常",Toast.LENGTH_SHORT).show();
                progressUtil.dismiss();
            }
        });
    }


    private void ly(final String mess, final int type){
        String data = lyJsonStrinf(mess, type);
        final ProgressUtil progressUtil = new ProgressUtil();
        progressUtil.ShowProgress(context,true,true,"正在留言...");
        HttpUtils httpUtils = new HttpUtils(3000);
        RequestParams params = new RequestParams();
        params.addBodyParameter("row1", "▶︎ @"+sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, "")+" 有新的留言");
        params.addBodyParameter("row2", "#"+title+"#");
        params.addBodyParameter("data", data);
        httpUtils.send(HttpMethod.POST, URLConstants.清单留言同步主留言信息, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    LYBreakBean lyBreakBean = gson.fromJson(responseInfo.result, LYBreakBean.class);
                    if (lyBreakBean.status == 0){
                        List<LYBreakBean.ListBean> list = lyBreakBean.list;
                        if (list != null){
                            for (LYBreakBean.ListBean bean : list){
                                insertLy(bean.newId, mess, type,lyBreakBean.downTime.replace("T"," "));
                            }
                        }
                        edit_tv.setText("");
                    }else {
                        Toast.makeText(QDFXDetailLYActivity.this,"留言失败",Toast.LENGTH_SHORT).show();
                    }
                }
                lyadapter();
                progressUtil.dismiss();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                Toast.makeText(QDFXDetailLYActivity.this,"网络异常",Toast.LENGTH_SHORT).show();
                progressUtil.dismiss();
            }
        });
    }

    private void insertLy(int newid,String mess, int type,String downTime){
        NoteLYBean.PageBean.ItemsBean bean = new NoteLYBean.PageBean.ItemsBean();
        bean.id = newid;
        bean.mess = mess;
        bean.uid = StringUtils.getIsIntEqulesNull(Integer.valueOf(uid));
        bean.lyUid = StringUtils.getIsIntEqulesNull(Integer.valueOf(userid));
        bean.lyName = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, "");
        bean.titleId = titleId;
        bean.cId = id;
        bean.localTimes = localTime;
        bean.changeTime = changeTime;
        bean.type = type;
        bean.reamrk1 = android.os.Build.MODEL.replace(" ","");
        bean.lyTitleImg = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERPHOTOPATH, "");
        bean.reamrk = title;
        bean.reamrk2 = "";

        App.getDBcApplication().insertNoteLYData(bean,downTime);
    }

    String localTime = "";
    String changeTime = "";

    private String lyJsonStrinf(String mess, int type){
        JSONObject ly = new JSONObject();
        localTime =  DateUtil.formatDateTimeSs(new Date());
        changeTime = DateUtil.formatDateTimeSs(new Date());
        try {
            JSONArray jsonArray = new JSONArray();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id", -1);
            jsonObject.put("mess", mess);
            jsonObject.put("updateState", 1);
            jsonObject.put("uid", uid);
            jsonObject.put("lyUid", userid);
            jsonObject.put("lyName", sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, ""));
            jsonObject.put("titleId", titleId);
            jsonObject.put("cId", id);
            jsonObject.put("localTimes", localTime);
            jsonObject.put("type", type);//0 普通留言 1 系统留言
            jsonObject.put("reamrk1", android.os.Build.MODEL.replace(" ","")+" "+android.os.Build.VERSION.RELEASE);
            jsonObject.put("lyTitleImg", sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERPHOTOPATH, ""));
            jsonObject.put("reamrk", title);
            jsonObject.put("changeTime",changeTime);
            jsonArray.put(jsonObject);
            ly.put("ly",jsonArray);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ly.toString();
    }

    class DelLYBean{
        /**
         * delList : null
         * downTime : 2017-07-31T14:41:19
         * list : null
         * message : 成功
         * status : 0
         * tDelList : null
         */

        public Object delList;
        public String downTime;
        public Object list;
        public String message;
        public int status;
        public Object tDelList;

        public Object getDelList() {
            return delList;
        }

        public void setDelList(Object delList) {
            this.delList = delList;
        }

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public Object getList() {
            return list;
        }

        public void setList(Object list) {
            this.list = list;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public Object getTDelList() {
            return tDelList;
        }

        public void setTDelList(Object tDelList) {
            this.tDelList = tDelList;
        }
    }

    public class LYBreakBean{

        /**
         * status : 0
         * downTime : 2017-07-24T13:23:05
         * message : 成功
         * list : [{"id":-1,"state":0,"newId":303,"dataState":1,"downTime":"2017-07-24T13:23:05"}]
         * tDelList : null
         * delList : null
         */

        public int status;
        public String downTime;
        public String message;
        public Object tDelList;
        public Object delList;
        public List<ListBean> list;

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public Object getTDelList() {
            return tDelList;
        }

        public void setTDelList(Object tDelList) {
            this.tDelList = tDelList;
        }

        public Object getDelList() {
            return delList;
        }

        public void setDelList(Object delList) {
            this.delList = delList;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public class ListBean {
            /**
             * id : -1
             * state : 0
             * newId : 303
             * dataState : 1
             * downTime : 2017-07-24T13:23:05
             */

            public int id;
            public int state;
            public int newId;
            public int dataState;
            public String downTime;

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public int getState() {
                return state;
            }

            public void setState(int state) {
                this.state = state;
            }

            public int getNewId() {
                return newId;
            }

            public void setNewId(int newId) {
                this.newId = newId;
            }

            public int getDataState() {
                return dataState;
            }

            public void setDataState(int dataState) {
                this.dataState = dataState;
            }

            public String getDownTime() {
                return downTime;
            }

            public void setDownTime(String downTime) {
                this.downTime = downTime;
            }
        }
    }

    public class QDBean {

        /**
         * status : 0
         * downTime : 2017-06-02T10:14:53
         * message : 成功
         * list : [{"ltype":1,"orderId":0,"states":2,"style":3,"remark1":null,"uname":"清流暖人心","cpath":"","remark2":null,"goodNum":5,"shareUrl":null,"contents":"七个戒烟方法","remark3":null,"isTop":0,"id":4504,"redNum":111,"remark4":null,"uid":260975,"num":"20170523172148548492","endstate":null,"imgUrl":"","remark5":null,"titleId":"20170523172045176901","titles":"七个戒烟方法","changeTime":"2017-05-25T11:47:32","remark6":null,"remark":"1","createTime":"2017-05-23T17:21:48","curl":"","imgPath":""}]
         * tDelList : null
         * delList : null
         */

        public int status;
        public String downTime;
        public String message;
        public Object tDelList;
        public Object delList;
        public List<ListBean> list;

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public Object getTDelList() {
            return tDelList;
        }

        public void setTDelList(Object tDelList) {
            this.tDelList = tDelList;
        }

        public Object getDelList() {
            return delList;
        }

        public void setDelList(Object delList) {
            this.delList = delList;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public class ListBean implements Serializable {
            /**
             * ltype : 1
             * orderId : 0
             * states : 2
             * style : 3
             * remark1 : null
             * uname : 清流暖人心
             * cpath :
             * remark2 : null
             * goodNum : 5
             * shareUrl : null
             * contents : 七个戒烟方法
             * remark3 : null
             * isTop : 0
             * id : 4504
             * redNum : 111
             * remark4 : null
             * uid : 260975
             * num : 20170523172148548492
             * endstate : null
             * imgUrl :
             * remark5 : null
             * titleId : 20170523172045176901
             * titles : 七个戒烟方法
             * changeTime : 2017-05-25T11:47:32
             * remark6 : null
             * remark : 1
             * createTime : 2017-05-23T17:21:48
             * curl :
             * imgPath :
             */

            public int ltype;
            public int orderId;
            public int states;
            public int style;
            public String remark1;
            public String uname;
            public String cpath;
            public String remark2;
            public int goodNum;
            public String shareUrl;
            public String contents;
            public String remark3;
            public int isTop;
            public int id;
            public int redNum;
            public String remark4;
            public int uid;
            public String num;
            public int endstate;
            public String imgUrl;
            public String remark5;
            public String titleId;
            public String titles;
            public String changeTime;
            public String remark6;
            public String remark;
            public String createTime;
            public String curl;
            public String imgPath;

            public int getLtype() {
                return ltype;
            }

            public void setLtype(int ltype) {
                this.ltype = ltype;
            }

            public int getOrderId() {
                return orderId;
            }

            public void setOrderId(int orderId) {
                this.orderId = orderId;
            }

            public int getStates() {
                return states;
            }

            public void setStates(int states) {
                this.states = states;
            }

            public int getStyle() {
                return style;
            }

            public void setStyle(int style) {
                this.style = style;
            }

            public String getRemark1() {
                return remark1;
            }

            public void setRemark1(String remark1) {
                this.remark1 = remark1;
            }

            public String getUname() {
                return uname;
            }

            public void setUname(String uname) {
                this.uname = uname;
            }

            public String getCpath() {
                return cpath;
            }

            public void setCpath(String cpath) {
                this.cpath = cpath;
            }

            public String getRemark2() {
                return remark2;
            }

            public void setRemark2(String remark2) {
                this.remark2 = remark2;
            }

            public int getGoodNum() {
                return goodNum;
            }

            public void setGoodNum(int goodNum) {
                this.goodNum = goodNum;
            }

            public String getShareUrl() {
                return shareUrl;
            }

            public void setShareUrl(String shareUrl) {
                this.shareUrl = shareUrl;
            }

            public String getContents() {
                return contents;
            }

            public void setContents(String contents) {
                this.contents = contents;
            }

            public String getRemark3() {
                return remark3;
            }

            public void setRemark3(String remark3) {
                this.remark3 = remark3;
            }

            public int getIsTop() {
                return isTop;
            }

            public void setIsTop(int isTop) {
                this.isTop = isTop;
            }

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public int getRedNum() {
                return redNum;
            }

            public void setRedNum(int redNum) {
                this.redNum = redNum;
            }

            public String getRemark4() {
                return remark4;
            }

            public void setRemark4(String remark4) {
                this.remark4 = remark4;
            }

            public int getUid() {
                return uid;
            }

            public void setUid(int uid) {
                this.uid = uid;
            }

            public String getNum() {
                return num;
            }

            public void setNum(String num) {
                this.num = num;
            }

            public int getEndstate() {
                return endstate;
            }

            public void setEndstate(int endstate) {
                this.endstate = endstate;
            }

            public String getImgUrl() {
                return imgUrl;
            }

            public void setImgUrl(String imgUrl) {
                this.imgUrl = imgUrl;
            }

            public String getRemark5() {
                return remark5;
            }

            public void setRemark5(String remark5) {
                this.remark5 = remark5;
            }

            public String getTitleId() {
                return titleId;
            }

            public void setTitleId(String titleId) {
                this.titleId = titleId;
            }

            public String getTitles() {
                return titles;
            }

            public void setTitles(String titles) {
                this.titles = titles;
            }

            public String getChangeTime() {
                return changeTime;
            }

            public void setChangeTime(String changeTime) {
                this.changeTime = changeTime;
            }

            public String getRemark6() {
                return remark6;
            }

            public void setRemark6(String remark6) {
                this.remark6 = remark6;
            }

            public String getRemark() {
                return remark;
            }

            public void setRemark(String remark) {
                this.remark = remark;
            }

            public String getCreateTime() {
                return createTime;
            }

            public void setCreateTime(String createTime) {
                this.createTime = createTime;
            }

            public String getCurl() {
                return curl;
            }

            public void setCurl(String curl) {
                this.curl = curl;
            }

            public String getImgPath() {
                return imgPath;
            }

            public void setImgPath(String imgPath) {
                this.imgPath = imgPath;
            }
        }
    }
}
